package combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Doream
 * @Date: 2022/1/28 21:10
 */

// 菜单类，属于树枝节点
public class Menu extends MenuComponent{
    // 菜单可以有多个子菜单或菜单项
    private List<MenuComponent> menuComponentList = new ArrayList<>();

    public Menu(String name,int level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponentList.get(index);
    }

    @Override
    public void print() {
        // 打印菜单名称
        System.out.print("菜单："+this.name+"{");
        // 打印子菜单

        for (MenuComponent menuComponent : menuComponentList) {
            menuComponent.print();
        }
        System.out.print("}");
    }
}
